package com.example.pushapplication.live;

import android.app.Activity;
import android.view.SurfaceHolder;

import com.example.pushapplication.live.channel.AudioChannel;
import com.example.pushapplication.live.channel.VideoChannel;

public class LivePusher {
    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }
    private VideoChannel videoChannel;
    private AudioChannel audioChannel;
    public LivePusher(Activity activity, int width, int height, int bitrate,
                      int fps, int cameraId){

        native_init();

        videoChannel = new VideoChannel(this,activity, width, height, bitrate, fps, cameraId);
        audioChannel = new AudioChannel(this);
    }

    public void startLive(String url) {

        native_start(url);
        videoChannel.startLive();
        audioChannel.startLive();
    }

    public void setPreviewDisplay(SurfaceHolder surfaceHolder) {
        videoChannel.setPreviewDisplay(surfaceHolder);
    }
    public void stopLive() {
        videoChannel.stopLive();
        audioChannel.stopLive();
    }




    public native void native_start(String path);

    public native void native_init();
    //初始化编码器   在打开相机后回调
    public native void native_setVideoEncInfo(int width, int height, int fps, int bitrate);

    //发送数据
    public native void native_pushVideo(byte[] data);

    // sampleRateInHz 44100 channels 双同道  初始化编发器
    public native void native_setAudioEncInfo(int sampleRateInHz, int channels);

    public native int getInputSamples();

    public native void native_pushAudio(byte[] bytes) ;
}
